/************************************************************
 * Copyright (C), 2022-2030, dina. Co., Ltd.
 * FileName:        mutil_header.h
 * Author:          Dan Yin
 * Date:            2024-09-10
 * Description:     QHeaderView sub-class
 * Version:         1.0.0.0
 **********************************************************/

#ifndef MUTIL_HEADER_H
#define MUTIL_HEADER_H

#include <QHeaderView>
#include <QMetaType>
#include <QPainter>

struct SpanRange
{
    int startRow = -1;
    int startCol = -1;
    int endRow = -1;
    int endCol = -1;

    bool isValid() {
        if (startRow < 0 || startCol < 0 || endRow < 0 || endCol < 0) {
            return false;
        }

        return true;
    }
};
Q_DECLARE_METATYPE(SpanRange);

class MutilHeader : public QHeaderView
{
    Q_OBJECT

public:
    MutilHeader(Qt::Orientation orientation, QWidget *parent = nullptr);
    ~MutilHeader();

    void setLabels(const QList<QStringList> &headers);

    void setRowHeight(int hight);

    void setSpanRange(const SpanRange &range);

protected slots:
    void onSectionResized(int logicalIndex, int oldSize, int newSize);

protected:
    virtual void paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const;

    virtual QSize sectionSizeFromContents(int logicalIndex) const;

protected:
    int _rowHight = 28;
};

#endif // MUTIL_HEADER_H
